[#include "../../../common/html.ftl" /]
[@html]
    [@head title="菜单列表" css=["fw", "bootstrap-treetable-ajax"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="system:menu:remove"]--]
                    <button class="am-btn am-btn-success am-radius" onclick="$.operate.addFull(0)">添加</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:menu:remove"]--]
                    [#--<button class="am-btn am-btn-danger am-radius" onclick="clearCache()">清除缓存</button>--]
                    [#--[/@shiro.hasPermission]--]
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-menu-search" searchFun="$.treeTable.search()" ]
                    <div class="am-form-group">
                        <input type="text" name="menuName" class="am-form-field am-input-sm am-radius" placeholder="菜单名称">
                    </div>
                    <div class="am-form-group">
                        <select name="visible" class="am-radius" data-am-selected placeholder="菜单状态">
                            <option value=""></option>
                            [#list dict.getType("sys_menu_visible") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <select name="buildIn" class="am-radius" data-am-selected placeholder="是否内置菜单">
                            <option value=""></option>
                            [#list dict.getType("sys_yes_no") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-tree-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-treetable-ajax"]]
            <script type="text/javascript">
                [#--var addFlag = "${hasPermission('system:menu:add')}";--]
                [#--var editFlag = "${hasPermission('system:menu:edit')}";--]
                [#--var removeFlag = "${hasPermission('system:menu:remove')}";--]
                var addFlag = "";
                var editFlag ="";
                var removeFlag ="";
                var datas = ${convert.toJson(dict.getType("sys_menu_visible"))};
                var datasYesNo = ${convert.toJson(dict.getType("sys_yes_no"))};
                var isAdministrator = ${convert.toJson(common.isAdministrator())};
                var prefix = ctx + "osfw/system/manage/menu";

                $(function () {
                    var options = {
                        code: "menuId",
                        parentCode: "parentId",
                        uniqueId: "menuId",
                        expandColumn: 0,
                        expandAll: false,
                        expandFirst: false,
                        url: prefix + "/listImmediateChildren",
                        createUrl: prefix + "/add/{id}",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove/{id}",
                        layerHeight: 650,
                        modalName: "菜单",
                        columns: [
                            {
                                field: 'menuName',
                                title: '菜单名称',
                                width: '20%',
                                formatter: function(value, row, index) {
                                    if ($.common.isEmpty(row.icon)) {
                                        return row.menuName;
                                    } else {
                                        return '<i class="' + row.icon + ' am-icon-fw"></i> <span class="nav-label">' + row.menuName + '</span>';
                                    }
                                }
                            },
                            {
                                field: 'orderNum',
                                title: '排序',
                                width: '10%',
                            },
                            {
                                field: 'url',
                                title: '请求地址',
                                width: '15%',
                                visible: false,
                                formatter: function(value, row, index) {
                                    return $.table.tooltip(value);
                                }
                            },
                            {
                                title: '类型',
                                field: 'menuType',
                                width: '10%',
                                formatter: function(value, item, index) {
                                    if (item.menuType == 'M') {
                                        return '<span class="am-badge am-badge-success am-radius">目录</span>';
                                    }
                                    else if (item.menuType == 'C') {
                                        return '<span class="am-badge am-badge-primary am-radius">菜单</span>';
                                    }
                                    else if (item.menuType == 'F') {
                                        return '<span class="am-badge am-badge-warning am-radius">按钮</span>';
                                    }
                                }
                            },
                            {
                                field: 'visible',
                                title: '可见',
                                width: '10%',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(datas, row.visible);
                                }
                            },
                            {
                                visible: isAdministrator ? true : false,
                                switchable: isAdministrator ? true : false,
                                field: 'buildIn',
                                title: '系统内置',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datasYesNo, value);
                                }
                            },
                            {
                                field: 'perms',
                                title: '权限标识',
                                width: '15%',
                                visible: false,
                                formatter: function(value, row, index) {
                                    return $.table.tooltip(value);
                                }
                            },
                            {
                                title: '操作',
                                width: '20%',
                                formatter: function(value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.addFull(\'' + row.menuId + '\')">添加</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.menuId + '\')">编辑</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.menuId + '\')">删除</a> ');
                                    return actions.join('');
                                }
                            }
                        ]
                    };
                    $.treeTable.init(options);
                });

                /** 清理字典缓存 */
                function clearCache() {
                    $.operate.get(prefix + "/clearCache");
                }

            </script>
        [/@script]
    [/@body]
[/@html]
